﻿function getPropertyValue(remotePtr, propName) {

}

function setPropertyValue(remotePtr, propName) {

}

function evalFunc(remotePtr,propName) {
    
}

var ptrmapper = {};

function __getJsProxyByKey(elementID) {
    var obj = ptrmapper[elementID];

    if (typeof obj == "undefined" || obj==null) {
        throw Error('对象不存在');
    }

    if (obj.__isProxy) {
        return obj;
    }


    obj= new Proxy(obj,
        {
            get: function (target, propertyName) {
                if (propertyName=="__isProxy") {
                    return true;
                }

                return Reflect.get(target, propertyName);
            },
            set: function (target, propertyName, value,receiver) {
                Reflect.set(target, propertyName, value, receiver);
                //target[propertyName] = value;
            },
            apply: function (target, thisArgument, argumentsList) {

                return Reflect.apply(target, thisArgument, argumentsList);
            }
        });

    ptrmapper[elementID] = obj;

    return obj;
}

/**
 * 输出变量名获取对应的代理对象
 * @param {any} varName 
 */
function __getJsProxyByVar(varName) {
    return ptrmapper[varName];
}


function __deleteJsProxyByVar(varName) {
    ptrmapper.remove(varName);
}

function _createElementProxyByID(elementID) {
    if (!ptrmapper.hasOwnProperty(elementID)) {
        var el = document.getElementById(elementID);

        if (el==null) {
            return false;
        }

        ptrmapper[elementID] = el;
        return true;
    } else {
        return true;
        //throw "Element not exists";
    }
}


var razorUI = new Proxy({},
    {
        //直接返回调用的函数
        get: function (target, propertyName) {
            var p = propertyName;
      
            return new function () {
                return cSharpRazorUI.proxyCall(p, arguments);
            }
        }
    });


document.addEventListener("DOMContentLoaded", function() {
   // cSharpRazorUI.proxyCall("__formloaded");
    //razorUI.__formloaded();
});